#include "stdafx.h"
#include "Wall.h"
#include "AttackWallMediator.h"

Wall::Wall(const EEntityType& entity_type, AttackWallMediator* attack_wall_mediator) 
	: Entity(entity_type), m_attack_wall_mediator(attack_wall_mediator)
{
}

Wall::~Wall(void)
{
	m_attack_wall_mediator->RemoveTarget();
}

void Wall::Init(SceneObject* scene_object, Grid* grid)
{
	m_scene_object = scene_object;
	m_grid = grid;

	m_health = 5;
	m_attack_wall_mediator->AddTarget(this);
}

void Wall::Update(float deltatime)
{
	m_scene_object->m_transform = DirectX::XMMatrixTranslation(m_position.x, m_position.y, m_position.z);
	m_scene_object->m_bounding_sphere.m_position = Vec3(m_position.x, m_position.y, m_position.z);
	m_collider->Update(m_position);

	if (m_health <= 0)
		RemoveMe();
}

void Wall::SetGridPosition(unsigned int x, unsigned int y)
{
	m_position = m_grid->GetSquare(x, y).m_position;
}